#pragma once

#include "../im.h"

class IMUser;
typedef std::shared_ptr<IMUser> IMUserPtr;
class IMGroup
{
private:
    std::list<IMUserPtr> users_; // 群成员 这里为什么不使用vector呢 因为list删除元素效率更高
    IMUserPtr owner_;
    IMUserPtr creator_;
    std::string dec_; // 群描述
    std::string name_;
    groupid_t gid_;

public:
    IMGroup(const IMUserPtr &owner, const IMUserPtr &creator, const std::string &name, const groupid_t &gid, const std::string &dec = "")
        : owner_(owner), creator_(creator), name_(name), dec_(dec), gid_(gid)
    {
        // creator_ = owner;
    }

public:
    void addUser(const userid_t &uid);
    void addUser(const IMUserPtr &user);

    void removeUser(const userid_t &uid);
    void removeUser(const IMUserPtr &user);
    // 解散
    void removeAll();

    groupid_t getId() const { return gid_; }
    const std::string &getName() const { return name_; }
    const std::string &getDec() const { return dec_; }
    const IMUserPtr &getOwner() const { return owner_; }
    const IMUserPtr &getCreator() const { return creator_; }
    const std::list<IMUserPtr> &getUsers() const { return users_; }
};
typedef std::shared_ptr<IMGroup> IMGroupPtr;